package com.elangzhi.ssm.modules.user.services;

import com.alibaba.fastjson.JSONObject;
import com.elangzhi.ssm.tools.HttpUtil;
import com.elangzhi.ssm.tools.ProjectConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Thinks方接口
 */
@Service
public class ThinksService {

    @Autowired
    private ProjectConfig projectConfig;


  /**
     * 修改信息
     * @param userName 用户
     * @param nick 昵称
     * @param wechat 微信
     * @param qq QQ号
     * @return 结果
     */
    public JSONObject userEdit(String userName,String nick,String wechat,String qq){
        String sourceUrl = "/Api/Userapi/editInfo/username/${userName}/nick/${nick}/wechat/${wechat}/qq/${qq}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${nick}",nick);
        sourceUrl = sourceUrl.replace("${wechat}",wechat);
        sourceUrl = sourceUrl.replace("${qq}",qq);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 修改密码
     * @param userName 用户
     * @param newPassword 新密码
     * @return 结果
     */
    public JSONObject passwordEdit(String userName,String newPassword){
        String sourceUrl = "/Api/Userapi/editPass/username/${userName}/newpass/${newPassword}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${newPassword}",newPassword);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 转账
     * @param userName 用户
     * @param vicename 对方用户
     * @param num 数量
     * @return 结果
     */
    public JSONObject zhuanzhang(String userName,String vicename,String num){
        String sourceUrl = "/Api/Currencyapi/index/username/${userName}/vicename/${vicename}/num/${num}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${num}",num);
        sourceUrl = sourceUrl.replace("${vicename}",vicename);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 消费
     * @param userName 用户
     * @param num T币数量
     * @return 结果
     */
    public JSONObject xiaofei(String userName,String num){
        String sourceUrl = "/Api/Currencyapi/index/username/${userName}/num/${num}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${num}",num);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 获取个人钱包信息
     * @param userName 用户名
     * @return 结果
     */
    public JSONObject currency(String userName){
        String sourceUrl = "/Api/Currencyapi/currencyDetail/username/${userName}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 获取个人信息
     * @param userName 用户名
     * @return 结果
     */
    public JSONObject selectUser(String userName){
        String sourceUrl = "/Api/Userapi/user/username/${userName}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 注册 用户
     * @param userName 用户名
     * @param password 密码
     * @param phone 手机号
     * @param nick 昵称
     * @param recup 上级
     * @return 结果
     */
    public JSONObject register(String userName, String password,String  phone,String nick,String recup){
        String sourceUrl = "/Api/Userapi/regUser/username/${userName}/pass/${password}" +
                "/nick/${nick}/phone/${phone}/recup/${recup}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${password}",password);
        sourceUrl = sourceUrl.replace("${phone}",phone);
        sourceUrl = sourceUrl.replace("${nick}",nick);
        sourceUrl = sourceUrl.replace("${recup}",recup);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }

    /**
     * 登录
     * @param userName 用户名
     * @param password 密码
     * @return 结果
     */
    public JSONObject login(String userName, String password){
        String sourceUrl = "/Api/Userapi/login/username/${userName}/password/${password}";
        sourceUrl = sourceUrl.replace("${userName}",userName);
        sourceUrl = sourceUrl.replace("${password}",password);
        return HttpUtil.get(projectConfig.getThinksHost() + sourceUrl);
    }





}
